<?php

class main extends Zcontroller {
	
	function __construct() {
		parent::__construct();
		//menu current page
		Zsession::setDataToSession("current_page", "home");	
        //$this->load_translation(array("job"));
        $this->getVisitor();
        
        
	}
	
	public function index()
	{   	
			//$Z_TRANS = Translation::getInstance();
            $this->load->helper('url_helper');
            $this->load->model("job_announcement_model");
            
            $this->load->model("m_property");
            $this->load->model("m_jobwanted");
			$this->load->model("model_vote_management");
			
			$this->load->model("m_classify");
			$data['all_cate']=$this->m_classify->get_all_classifycategory();
			
            $data['announcements']=$this->job_announcement_model->selectLatestJobAnnouncements(5);
            $data['all_ads']=$this->m_classify->get_product_main();
            $data['result_pro']=$this->m_property->get_property_main();
            $data['events']=$this->model_vote_management->selectHomeEvent();
            $data['jobwanted']=$this->m_jobwanted->get_job_wanted_main();
            
            $data['latest_ads']=$this->m_classify->get_product_latest();
            $data['view_all_ads']=$this->m_classify->get_view_all_ads();
            
            $data['cat_car']=$this->m_classify->get_view_by_cat("1");
            $data['cat_phone']=$this->m_classify->get_view_by_cat("3");
            $data['cat_phone_acc']=$this->m_classify->get_view_by_cat("19");
            $data['cat_computer']=$this->m_classify->get_view_by_cat("2");
            $data['cat_computer_acc']=$this->m_classify->get_view_by_cat("7");
            $data['cat_books']=$this->m_classify->get_view_by_cat("15");
            $data['cat_camera']=$this->m_classify->get_view_by_cat("8");
            
            $data['cat_cloth']=$this->m_classify->get_view_by_cat("12");
            $data['cat_dvd']=$this->m_classify->get_view_by_cat("14");
            $data['cat_flower']=$this->m_classify->get_view_by_cat("13");
            $data['cat_Health']=$this->m_classify->get_view_by_cat("16");
            
            $data['cat_Home_app']=$this->m_classify->get_view_by_cat("10");
            $data['cat_Health']=$this->m_classify->get_view_by_cat("16");
            $data['cat_property']=$this->m_classify->get_view_properties();
            $data['cat_jewellery']=$this->m_classify->get_view_by_cat("9");
            
            $data['cat_motorbike']=$this->m_classify->get_view_by_cat("18");
            $data['cat_jewellery']=$this->m_classify->get_view_by_cat("9");
            $data['cat_other']=$this->m_classify->get_view_by_cat("11");
            
            $data['cat_job_wanted']=$this->m_classify->get_view_job_wanted();
            $data['cat_job_ann']=$this->m_classify->get_view_job_ann();
          
            $this->load->template("templates/general","index","Zuka: ".$this->z_tran->value('website_title'),$data);
    }
    
    
    function privacy_policy() {
    		$this->load->template("templates/general","privacy_policy","privacy_policy - Zuka: Classified ads | Job announment | Job wanted | Property | Vote!");
    }
    
    function term_of_user() {
    		$this->load->template("templates/general","termofuse","Term of use - Zuka: Classified ads | Job announment | Job wanted | Property | Vote!");
    }
    
    function contact_us() {
    		$this->load->template("templates/general","contactus","Contact us - Zuka: Classified ads | Job announment | Job wanted | Property | Vote!");
    }
    
 	function choose_lang($lang_code) {
 		$this->load->model("m_translate");
 		$languages = $this->m_translate->getLanguages(APPLICATION_ID); 
 		
	    Zsession::setLanguage($languages[$lang_code], $lang_code);
	    
	    $current_url = Zencryption::decrypt($_GET["curl"]);
	    redirect($current_url);
    }
    
    function cpanel(){
    	$this->load->model("front_m_job");
        $this->load->model("m_classify");
        $this->load->model("m_property");
        $this->load->model("m_main");
        $this->load->model("m_jobwanted");
		$this->load->model("model_vote_management");
		$this->load->library('pagination');
		
    	$Z_TRANS = Translation::getInstance();
    	
    	$data =array();
    	$config=array();
    	$config['base_url'] = base_url().'index.php/main/cpanel/';
    	$total_ads=$this->m_classify->count_ads();
      	$config['total_rows'] = count($total_ads->result());
      	$config['per_page'] = '10';
      	$config['full_tag_open'] = '<p>';
      	$config['full_tag_close'] = '</p>';
      	$this->pagination->initialize($config);
    	$data['all_ads']=$this->m_classify->select_all_product_ads($config['per_page'],$this->uri->segment(3));
    	$data['all_cate']=$this->m_classify->get_all_classifycategory();
    	$this->load->view("cPanel/classified",$data);
    	
    	//$data['all_ads']=$this->m_main->select_all_product_ads($config['per_page'],$this->uri->segment(3));
    	//$this->load->view("cPanel/classified", $Z_TRANS->value('menu_classified_ads'),$data);
    }
    
    function testMain(){
    	$this->load->model("m_jobwanted");
    	$data['jobwanted']=$this->m_jobwanted->get_job_wanted_main();
    	$this->load->view("testIndex",$data);
    	
    }
    
    function del_cassified($pro_id){
    	
    	$this->load->model("m_classify");
    	$this->load->model("m_main");
	    $Z_USER = Zsession::getUserFromSession();
		
		$userid=$Z_USER["user_id"];
		
    	$data['all_img']=$this->m_main->select_classify_img($pro_id);
	    foreach($data['all_img']->result() as $imgname):
		    $str_path = str_replace("\\", "/", FCPATH);
		    $img_big=$str_path.$imgname->file_path.$imgname->img_name;
		    
		    $file_name = current(explode(".", $imgname->img_name));
			$file_ext  = next(explode(".", $imgname->img_name));
			$img_thum = $str_path.$imgname->file_path.$file_name."_Thumb.".$file_ext;
		    
		    unlink($img_thum);
		    unlink($img_big);
		    $this->m_classify->delete_one_img($imgname->img_id,$pro_id);
	    endforeach;
	    //delete in table hits
	    $this->m_classify->delete_product_hit($pro_id);
	    //delete in table product_ads
	    $this->m_classify->delete_product_ads($pro_id);
	    	
    }
    
	function shop($id)
	{ 	
		$this->load->model("m_classify");
		$this->load->library('pagination');
		$Z_TRANS = Translation::getInstance();
    	
    	$data =array();
    	$config=array();
    	$config['base_url'] = base_url().'index.php/classify/page/';
    	$total_ads=$this->m_classify->count_ads();
      	$config['total_rows'] = count($total_ads->result());
      	$config['per_page'] = '26';
      	$config['num_links'] = '9';
      	$config['full_tag_open'] = '<p>';
      	$config['full_tag_close'] = '</p>';
      	$this->pagination->initialize($config);
      	
		$data['all_ads']=$this->m_classify->select_all_product_ads($config['per_page'],$this->uri->segment(3));
		$this->load->view("shop/shop",$data);
	}
    
}
?>
